Skip to content

✨ KCP: add KubeadmControlPlaneTemplate type #4904

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 26, 2021

Conversation

ykakarap
Copy link
Contributor

@ykakarap ykakarap commented Jul 9, 2021

What this PR does / why we need it:
Add KubeadmControlPlaneTemplate type to controlplane provider. This type will be used by ClusterClass.

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
Fixes #4901

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Jul 9, 2021
@k8s-ci-robot k8s-ci-robot added the size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. label Jul 9, 2021
Copy link
Member

@fabriziopandini fabriziopandini left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ykakarap thanks for this PR!

Could you kindly enable web hooks for the new type ensuring that template type applies the same defaulting & validation rules of the actual type, otherwise this could trigger continuous reconcile loop down the path when comparing the desired state (the KubeadmControlPlaneTemplate object) with the actual state (the instance of KubeadmControlPlane generated from the template)?

Copy link
Member

@sbueringer sbueringer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some nits

@@ -0,0 +1,56 @@
/*
Copyright The Kubernetes Authors.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Copyright The Kubernetes Authors.
Copyright 2021 The Kubernetes Authors.

Usually we add the year when the file was added here (I have no idea if that's mandatory though) (applies to all new files with copyright header)

SchemeBuilder.Register(&KubeadmControlPlaneTemplate{}, &KubeadmControlPlaneTemplateList{})
}

// KubeadmControlPlaneTemplateResource describes the data needed to create an KubeadmControlPlane from a template.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// KubeadmControlPlaneTemplateResource describes the data needed to create an KubeadmControlPlane from a template.
// KubeadmControlPlaneTemplateResource describes the data needed to create a KubeadmControlPlane from a template.

nit

@ykakarap ykakarap force-pushed the kcptemplate branch 4 times, most recently from acd0ff3 to 2142049 Compare July 13, 2021 22:36
@ykakarap
Copy link
Contributor Author

@fabriziopandini @sbueringer thanks for the review.

I addressed all the PR comments. Can you please review this again?

Copy link
Contributor

@srm09 srm09 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor nits

)

// log is for logging in this package.
var kubeadmcontrolplanetemplatelog = logf.Log.WithName("kubeadmcontrolplanetemplate-resource")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know the loggers are auto-generated, but the info messages do not add anything. Plus IIRC, controller-runtime logs all the webhook requests it receives. So that is covered.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@srm09 Afaik it doesn't log them on the default log level. But I wouldn't add log statements here. When we do it we should do it across the repo.

"sigs.k8s.io/cluster-api/util/version"
)

func (s *KubeadmControlPlaneSpec) validate(namespace string) (allErrs field.ErrorList) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One more suggestion about the method, since we are refactoring it, let's. break this down into smaller chunks aimed at specific parts of the object. For example, a separate method for s.Replicas, RolloutStrategy and so on.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 for that suggestion

Copy link
Member

@sbueringer sbueringer Jul 15, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm usually we don't break it down that far. Not really against splitting it up, but if it was intended as more or less one func per field I think that's a bit much.

@fabriziopandini wdyt?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI, some of the providers to see to be breaking down the validations to smaller functions. Ref: https://github.com/kubernetes-sigs/cluster-api-provider-azure/blob/master/api/v1alpha4/azuremachine_validation.go#L31-L59

@srm09
Copy link
Contributor

srm09 commented Jul 14, 2021

/assign @srm09

@ykakarap
Copy link
Contributor Author

/test pull-cluster-api-verify

@ykakarap
Copy link
Contributor Author

@fabriziopandini addressed all the comments on the PR and all pipelines are green.
Please review when you can.

@fabriziopandini
Copy link
Member

thanks for taking care of all the comments!
/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jul 19, 2021

if !reflect.DeepEqual(r.Spec.Template.Spec, old.Spec.Template.Spec) {
allErrs = append(allErrs,
field.Invalid(field.NewPath("KubeadmControlPlaneTemplate", "spec", "template", "spec"), r, kubeadmControlPlaneTemplateImmutableMsg),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
field.Invalid(field.NewPath("KubeadmControlPlaneTemplate", "spec", "template", "spec"), r, kubeadmControlPlaneTemplateImmutableMsg),
field.Invalid(field.NewPath("spec", "template", "spec"), r, kubeadmControlPlaneTemplateImmutableMsg),

Afaik we usually don't add the kind

// ValidateCreate implements webhook.Validator so a webhook will be registered for the type.
func (r *KubeadmControlPlaneTemplate) ValidateCreate() error {
spec := r.Spec.Template.Spec
allErrs := valdiateKubeadmControlPlaneSpec(spec, r.Namespace)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
allErrs := valdiateKubeadmControlPlaneSpec(spec, r.Namespace)
allErrs := validateKubeadmControlPlaneSpec(spec, r.Namespace)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typos 😂

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I use the Intellij spellchecker. ;)

// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type.
func (r *KubeadmControlPlaneTemplate) ValidateUpdate(oldRaw runtime.Object) error {
var allErrs field.ErrorList
old := oldRaw.(*KubeadmControlPlaneTemplate)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We usually seem to check if the type case works and then return an error (instead of a panic which would happen otherwise), e.g.:

        oldM, ok := old.(*Machine)
	if !ok {
		return apierrors.NewBadRequest(fmt.Sprintf("expected a Machine but got a %T", old))
	}

Copy link
Member

@sbueringer sbueringer Jul 20, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you also fix it in the KubeadmControlPlane webhook please? (that one was already there before your PR :))

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added the checks in both the places now :)
I dont think the check was present before (or atleast I didnt find it 😅 ).
Anyway, it should be taken care now.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was referring to that one:

@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jul 20, 2021
@sbueringer
Copy link
Member

Thx!
/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jul 20, 2021
@fabriziopandini
Copy link
Member

/lgtm
@vincepri PTAL

Copy link
Member

@vincepri vincepri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/approve

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: vincepri

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added approved Indicates a PR has been approved by an approver from all required OWNERS files. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. labels Jul 26, 2021
@k8s-ci-robot k8s-ci-robot removed lgtm "Looks good to me", indicates that a PR is ready to be merged. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. labels Jul 26, 2021
@ykakarap
Copy link
Contributor Author

/retest

@sbueringer
Copy link
Member

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jul 26, 2021
@k8s-ci-robot k8s-ci-robot merged commit deea51d into kubernetes-sigs:master Jul 26, 2021
@k8s-ci-robot k8s-ci-robot added this to the v0.4 milestone Jul 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add KubeadmControlPlaneTemplate type
6 participants